package cn.mily.org.controller;

import cn.mily.basics.utils.JsonResult;
import cn.mily.basics.utils.PageBean;
import cn.mily.org.domain.Department;
import cn.mily.org.domain.Shop;
import cn.mily.org.query.DepartmentQuery;
import cn.mily.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    private IShopService service;

    /**
     * 注册商家
     * @param shop
     * @return
     */
    @PostMapping("/reg")
    public JsonResult RegShop(@RequestBody Shop shop){
        try {/*添加和修改*/
            if(shop.getId()!=null){
                service.updateState(shop);
            }else{
                service.regShop(shop);
            }
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult(e.getMessage());
        }
    };

    @PostMapping/*获取全部*/
    public PageBean<Shop> findAll(@RequestBody DepartmentQuery query){
        return service.findAll(query);
    }

}
